<?php
  include_once('../class_timer.php');
  require_once('./config.php');
  require_once('./tool_benchmark.php');

  $a = array();
  for($i=0;$i<$nb_iter;++$i){
    $a[] = $i;
  }

  function work1(&$_a){
    $j = 0;
    foreach($_a as $i=>$k){
      $j += $k;
    }
    return $j;
  }

  function work2(&$_a){
    $c = count($_a);
    $j = 0;
    for($i=0;$i<$c;++$i){
      $j += $_a[$i];
    }
    return $j;
  }


  function work3(&$_a){
    $c = count($_a);
    $j = 0;
    for($i=0;$i<$c;++$i){
      $j += $_a[$i];
    }
    return $j;
  }

  function work4(&$_a){
    $j = 0;
    reset($_a);
    while(list($i,$k) = each($_a)){
      $j += $k;
    }
    return $j;
  }


  $time1 = new Timer();
  $array_functions = array('work1', 'work2', 'work3', 'work4');
  Tool_benchmark::bench_array_functions($array_functions,$a,$nb_experiences,$time1);
  $array_names = array('foreach()', 'for(++$i)', 'for($i++)', 'while(each)');
  Tool_benchmark::print_info_bench($array_names,$time1);
?>
